package com.lgq.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 *@author  刘光强
 *@date    2012-4-7 上午9:57:13
 *@version 1.0
 **/
public class SessionListener implements HttpSessionListener  {

	@Override
	public void sessionCreated(HttpSessionEvent event) {
		System.out.println("启动Session监听");
		Integer visitNum=(Integer)event.getSession().getServletContext().getAttribute("visitnum");
		Integer onlineNum=(Integer)event.getSession().getServletContext().getAttribute("onlinenum");
		visitNum=visitNum+1;
		onlineNum=onlineNum+1;
		event.getSession().getServletContext().setAttribute("visitnum", visitNum);
		event.getSession().getServletContext().setAttribute("onlinenum", onlineNum);
	}

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		Integer onlineNum=(Integer)event.getSession().getServletContext().getAttribute("onlinenum");
		onlineNum=onlineNum-1;
		event.getSession().getServletContext().setAttribute("onlinenum", onlineNum);
	}
	
}
